<?php

namespace App\Http\Controllers\H5appApi\Ding;

use Hash;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Support\Facades\Auth;
use App\Http\Models\Admin\Permission_;
use App\Http\Models\Admin\ClassifyPermissions;
use App\Http\Models\Admin\Role_;
use Illuminate\Support\Facades\Hash as FacadesHash;
use Illuminate\Support\Facades\DB;
use App\Http\Models\Admin\Member\Personnel;

use App\Http\Controllers\Traits\DingDingTrait;

class LoginController extends Controller
{
    use DingDingTrait;
    // use ThrottlesLogins;
    //用户登录
    public function Login(Request $request)
    {
        $code = $request->get('code');

        $result = self::getCodeToUser($code);
        // 执行登录操作

        if ($result != null && $result->errcode == 0) {
            return response()->json(['code' => 20000, 'message' => '登录成功',  'data' => $result]);
        } else {
            return response()->json(['code' => $result->errcode, 'message' => $result->errmsg]);
        }
    }
    // 获取jsapi参数
    public function getJsApiConfig()
    {
        $JsApiConfig= self::getJsApiConf();
        if (is_array($JsApiConfig)&&!is_object($JsApiConfig)) {
            return response()->json(['code' => 20000, 'message' => 'api配置获取成功！',  'config' => $JsApiConfig]);
        } else {
            return response()->json(['code' => $JsApiConfig->errcode, 'message' => $JsApiConfig->errmsg]);
        }
    }
}
